﻿<%@ Page Title="Quản lý thông tin tài xế" MasterPageFile="~/Admin/Site.Master" Language="C#" AutoEventWireup="true" CodeBehind="QLThongTinTaiXe.aspx.cs" Inherits="Transport.Admin.QLThongTinTaiXe" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<% 
    if (Session["loainguoidung"] == null)
    {
        Response.Redirect("../Default.aspx");
    }
    else
    {
        if (Session["loainguoidung"].ToString() != "ADMIN")
            Response.Redirect("Default.aspx");
    }  
    %>
    <p>
    <b>Mã tài xế:</b>
    <asp:TextBox ID="txt_ID" runat="server" />
    <b>Họ tên:</b>
    <asp:TextBox ID="txt_Name" runat="server" />
    <asp:Button ID="btnDisplayUsernames" runat="server" Text="Tìm" />
</p>
<p>
    <b>Tình trạng: </b>
    <asp:DropDownList ID="ddl_Status" runat="server" AutoPostBack="True" 
        DataSourceID="EntityDataSource_Status" DataTextField="ten_tinh_trang" 
        DataValueField="ma_tinh_trang" AppendDataBoundItems="true">
        <asp:ListItem text="Select All" value="-1" />
    </asp:DropDownList>
    <asp:EntityDataSource ID="EntityDataSource_Status" runat="server" 
        ConnectionString="name=transportEntities" 
        DefaultContainerName="transportEntities" EnableFlattening="False" 
        EntitySetName="tinh_trang_tai_xe" EntityTypeFilter="tinh_trang_tai_xe">
    </asp:EntityDataSource>
</p>
<div style="zoom: 1; overflow: auto;">
    <asp:GridView ID="GridView_Driver" runat="server" AllowPaging="True" 
        AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ma_tai_xe" CellSpacing="4"
        DataSourceID="EntityDataSource_Driver" ForeColor="#333333" GridLines="None">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:TemplateField HeaderText="Chọn">
                <ItemTemplate>
                    <asp:CheckBox ID="cb_Select" runat="server">
                    </asp:CheckBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="ma_tai_xe" HeaderText="Mã tài xế" ReadOnly="True" 
                SortExpression="ma_tai_xe" />
            <asp:BoundField DataField="ten" HeaderText="Họ tên" SortExpression="ten" />
            <asp:BoundField DataField="nam_sinh" HeaderText="Năm sinh" DataFormatString="{0:d}" ApplyFormatInEditMode="true"
                SortExpression="nam_sinh" />
            <asp:BoundField DataField="cmnd" HeaderText="Số CMND" SortExpression="cmnd" />
            <asp:BoundField DataField="dien_thoai" HeaderText="Điện thoại" 
                SortExpression="dien_thoai" />
            <asp:BoundField DataField="dia_chi" HeaderText="Địa chỉ" 
                SortExpression="dia_chi" />
            <asp:TemplateField HeaderText="Tình trạng">
                <ItemTemplate>
                    <asp:DropDownList ID="ddl_uStatus" runat="server" 
                        DataSourceID="EntityDataSource_Status" DataTextField="ten_tinh_trang" 
                        DataValueField="ma_tinh_trang" SelectedValue='<%# Bind("tinh_trang") %>'>
                    </asp:DropDownList>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddl_uStatus1" runat="server" 
                        DataSourceID="EntityDataSource_Status" DataTextField="ten_tinh_trang" 
                        DataValueField="ma_tinh_trang" SelectedValue='<%# Bind("tinh_trang") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="so_chuyen" HeaderText="Số chuyến" 
                SortExpression="so_chuyen" />
        </Columns>
        <FooterStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
        <SortedAscendingCellStyle BackColor="#FDF5AC" />
        <SortedAscendingHeaderStyle BackColor="#4D0000" />
        <SortedDescendingCellStyle BackColor="#FCF6C0" />
        <SortedDescendingHeaderStyle BackColor="#820000" />
    </asp:GridView>
    <asp:EntityDataSource ID="EntityDataSource_Driver" runat="server" 
        ConnectionString="name=transportEntities" 
        DefaultContainerName="transportEntities" EnableDelete="True" 
        EnableFlattening="False" EnableInsert="True" EnableUpdate="True" 
        EntitySetName="tai_xe" EntityTypeFilter="tai_xe"
        Where="it.tinh_trang = CASE WHEN @Status = '-1' THEN  it.tinh_trang ELSE @Status END" >
        <WhereParameters>
            <asp:ControlParameter ControlID="ddl_Status" Type="String"
                Name="Status" PropertyName="SelectedValue"/>
        </WhereParameters>
    </asp:EntityDataSource>
    <asp:QueryExtender ID="qeSearch" runat="server" TargetControlID="EntityDataSource_Driver">
        <asp:SearchExpression DataFields="ma_tai_xe" SearchType="Contains">
            <asp:ControlParameter ControlID="txt_ID" />
        </asp:SearchExpression>
        <asp:SearchExpression DataFields="ten" SearchType="Contains">
            <asp:ControlParameter ControlID="txt_Name" />
        </asp:SearchExpression>
        <asp:OrderByExpression DataField="ma_tai_xe" Direction="Ascending" />
    </asp:QueryExtender>
</div>
<p>
    <b>Cập nhật tự động tổng số chuyến với các tài xế đã chọn:</b>
    <asp:Button ID="btn_Update" runat="server" Text="Cập nhật" 
        onclick="btn_Update_Click" />
</p>
<p>
    <b>Cập nhật tự động tổng số chuyến với tất cả các tài xế:</b>
    <asp:Button ID="btn_UpdateAll" runat="server" Text="Cập nhật hết" 
        onclick="btn_UpdateAll_Click" />
</p>
<p>
    <asp:DetailsView ID="DetailsView_Driver" runat="server" Height="50px" 
        Width="125px" AutoGenerateRows="False" BackColor="White" BorderColor="#CCCCCC" 
        BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ma_tai_xe" 
        DataSourceID="EntityDataSource_Driver" DefaultMode="Insert" ForeColor="Black" 
        GridLines="Horizontal" FieldHeaderStyle-Wrap="false" 
        oniteminserted="DetailsView_Driver_ItemInserted">
        <EditRowStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />
        <Fields>
            <asp:BoundField DataField="ma_tai_xe" HeaderText="Mã tài xế" ReadOnly="True" 
                SortExpression="ma_tai_xe" />
            <asp:BoundField DataField="ten" HeaderText="Họ tên" SortExpression="ten" />
            <asp:BoundField DataField="nam_sinh" HeaderText="Năm sinh" DataFormatString="{0:d}"
                SortExpression="nam_sinh" />
            <asp:BoundField DataField="cmnd" HeaderText="Số CMND" SortExpression="cmnd" />
            <asp:BoundField DataField="dien_thoai" HeaderText="Điện thoại" 
                SortExpression="dien_thoai" />
            <asp:BoundField DataField="dia_chi" HeaderText="Địa chỉ" 
                SortExpression="dia_chi" />
            <asp:TemplateField HeaderText="Tình trạng">
                <InsertItemTemplate>
                    <asp:DropDownList ID="ddl_iStatus" runat="server" 
                        DataSourceID="EntityDataSource_Status" DataTextField="ten_tinh_trang" 
                        DataValueField="ma_tinh_trang" SelectedValue='<%# Bind("tinh_trang") %>'>
                    </asp:DropDownList>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="so_chuyen" HeaderText="Số chuyến" 
                SortExpression="so_chuyen" />
            <asp:CommandField ShowInsertButton="True" />
        </Fields>
        <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
        <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
    </asp:DetailsView>
</p>
</asp:Content>